#include "FloatChromosome.h"

FloatChromosome::FloatChromosome() : ComplexChromosome()
{
}

FloatChromosome::FloatChromosome(int size) :
        ComplexChromosome(size)
{
}

FloatChromosome::FloatChromosome(const FloatChromosome &other) :
        ComplexChromosome(other)
{
}

QVariant FloatChromosome::getRandomValue() const
{
    double temp = (qrand() / (static_cast<double>(RAND_MAX) + 1.0)) *
                  (maxValue.toDouble() - minValue.toDouble()) +
                  minValue.toDouble();
    return temp;
}

QString FloatChromosome::toString() const
{
    QString out("");

    for(int i=0;i<geneArray.size() - 1;++i)
        out += QString::number(geneArray[i].toDouble(),'g') + ", ";
    out += QString::number(geneArray.last().toDouble(),'g');

    return out;
}

Chromosome* FloatChromosome::duplicate() const
{
    return new FloatChromosome(*this);
}
